//
//  HomeViewController.swift
//  NetMusic
//
//  Created by PushMeBaby on 16/2/2.
//  Copyright © 2016年 CoderC. All rights reserved.
//

import UIKit

class HomeViewController: UIViewController {
    
    
    
    private let sliderBar = SliderToolBar(frame: CGRectZero)
    
    
    private let commentTableView = CommentTableViewController()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.redColor()
        
        view.addSubview(sliderBar)
        
        view.addSubview(commentTableView.view)
        
        setupLeftNavBarItem()
        
        
        
        let rightItem = PlayMusicViewButton(frame: CGRectMake(0 , 0 , 25 , 25))

        let rightNavBarItem  =  UIBarButtonItem(customView: rightItem)
        
        navigationItem.rightBarButtonItem = rightNavBarItem
        
        
        setupSearchBar()
        
    }
    
    func setupSearchBar() {
        let searchBar = SearchBar()
        searchBar.placeholder = "搜索音乐、歌词、电台"
        searchBar.font = UIFont.systemFontOfSize(12)
        searchBar.backgroundColor = UIColor.whiteColor()
        searchBar.bounds.size = CGSizeMake(OSScreenW - 110, 30)
        searchBar.layer.cornerRadius = 5
        searchBar.layer.masksToBounds = true
        
        
        navigationItem.titleView = searchBar
    }
    
    func setupLeftNavBarItem() {
        
        
        
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "cm2_rcd_start"), forState: UIControlState.Normal)
        button.bounds.size = CGSizeMake(25, 25)
        let leftNavBarItem  =  UIBarButtonItem(customView: button)
        navigationItem.leftBarButtonItem = leftNavBarItem
        
    }
    
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        
        sliderBar.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(view)
            make.right.equalTo(view)
            make.height.equalTo(44)
            make.top.equalTo(0)
        }
        commentTableView.view.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.view)
            make.right.equalTo(self.view)
            make.bottom.equalTo(self.view)
            make.top.equalTo(sliderBar.snp_bottom)
        }
        
    }
    
    
    
}
